package SwingView.Announcement;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import JDBC.InstructorAnnouncementActivities;
import SwingController.CmsPresenter;
import SwingModel.CmsAnnouncement;
import SwingModel.CmsUser;
import SwingView.CmsMainView;

public class ALAnnouncementPost implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		CmsUser user = CmsPresenter.user;
		CmsMainView mainView = CmsPresenter.mainView;
		
		if(mainView.getContentPanel().getAnmInstructorPage().validateAllInput()){
			CmsAnnouncement newAnm = mainView.getContentPanel().getAnmInstructorPage().getComposedAnnouncement();
			String courseID = user.getSelectedCourse().getCourseID();
			InstructorAnnouncementActivities.postAnnouncement(courseID, newAnm);
			
			mainView.getContentPanel().getAnmInstructorPage().clearAllInput();
			
			mainView.displayAnnouncementInstructorPage(InstructorAnnouncementActivities.getListOfAnnouncement(user.getUsername(), courseID));
		}
	}

}
